using Microsoft.AspNetCore.Http;
using System;
using ManaSky.SSO.Helpers;
using ManaSky.SSO.Interface;
using ManaSky.SSO.Models;
using Microsoft.Extensions.Options;
using ManaSky.Common.Infos;

namespace ManaSky.SSO.Service
{
    /// <summary>
    /// 用户信息
    /// </summary>
    public class Auth : IAuth
    {
        private IHttpContextAccessor _httpContextAccessor;

        public Auth(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        ///  获取Token
        /// </summary>
        /// <returns></returns>
        private string GetToken()
        {
            string token = _httpContextAccessor.HttpContext.Request.Headers["Authorization"].ToString();
            return token;
        }

        /// <summary>
        /// 获取当前登录的用户信息
        /// </summary>
        /// <returns></returns>
        public CurrentUserInfo GetCurrentUser()
        {
            var token = GetToken();
            var currentUser =  JwtHelper.DecodeToUser(token);
            return currentUser;
        }
    }
}